﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PlanoAula.BD;

namespace PlanoAula.Repository
{
    public interface IPlanoAulaDetalheRepository : IGenericRepository<PlanoAulaDetalhe, dbDataContext>
    {
        bool DiaCadastrado(Guid PlanoAulaId, DateTime data);
        IList<PlanoAulaDetalhe> ObterDetalhesDoPlanoAula(Guid PlanoAulaId);

        bool DiaJaCadastrado(Guid PlanoAulaCabId, DateTime data);
    }
    public class PlanoAulaDetalheRepository : GenericRepository<PlanoAulaDetalhe, dbDataContext>, IPlanoAulaDetalheRepository
    {
        public bool DiaCadastrado(Guid PlanoAulaId, DateTime data)
        {
            return (from p in this.GetAll()
                    where p.PlanoAulaCab.Id == PlanoAulaId && p.Data.ToShortDateString() == data.ToShortDateString() &&
                    (p.DiaAula.HoraInicio * 60 + p.DiaAula.MinutoInicio) >= (data.Hour * 60 + data.Minute) &&
                    (p.DiaAula.HoraFinal * 60 + p.DiaAula.MinutoFinal) <= (data.Hour * 60 + data.Minute)
                    select p).Count() >= 1;
        }

        public IList<PlanoAulaDetalhe> ObterDetalhesDoPlanoAula(Guid PlanoAulaId)
        {
            return this.GetAll().Where(p => p.PlanoAulaCab.Id == PlanoAulaId).ToList();
        }
        public bool DiaJaCadastrado(Guid PlanoAulaCabId, DateTime data)
        {
            return this.GetAll().Count(p => p.PlanoAulaCab.Id == PlanoAulaCabId && p.Data.Date == data.Date) > 0;
        }

    }
}
